<%@page import="com.fractalist.man.constants.ManConstants"%>
<%@page import="com.fractalist.base.core.constants.SystemConstants"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	pageContext.setAttribute("baseweburl",
			SystemConstants.UPLOAD_WEB_URL);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>节目</title>
<link rel="stylesheet" href="${ctx }/css/styles.css" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.form.js"></script>
<jsp:include page="/common/jscalendar.jsp"></jsp:include>
</head>
<body style="overflow-y: scroll;">
	<script>
		var baseweburl = "${baseweburl}";

		function uploadFm() {
			var options = {
				url : '${ctx}/manager/uploadFm.action',
				type : "POST",
				dataType : "json",
				success : function(result) {
					var code = result.data.code;
					var url = result.data.url;
					if (code == 0) {
						$("#url").html(url);
					} else {
						alert(result.data.message);
					}
				}
			};
			$("#uploadForm2").ajaxSubmit(options);
		}

		function uploadImage() {
			var options = {
				url : '${ctx}/manager/uploadImgBase.action',
				type : "POST",
				dataType : "json",
				success : function(result) {
					var code = result.data.code;
					var url = result.data.url;
					if (code == 0) {
						alert("已上传成功");
						$("#iconDiv")
								.html(
										'<img src="' + url +'" /><input type="hidden" id="iconUrl" value="' + url +'" />');
					} else {
						alert(result.data.message);
					}
				}
			};
			$("#uploadForm").ajaxSubmit(options);
		}

		function createFm() {
			var title = $("#title").val();
			var iconUrl = $("#iconUrl").val();
			var url = $("#url").html();
			if (title == "") {
				alert("请输入节目的名称");
				return;
			}
			if (!url || url == "") {
				alert("请上传一个图标");
				return;
			}
			if (!iconUrl || iconUrl == "") {
				alert("请上传mp3文件的节目");
				return;
			}
			$.post("${ctx}/manager/createFm.action", {
				title : title,
				iconUrl : iconUrl,
				fmUrl : url,
				fmId : $("#fmId").val()
			}, function(data) {
				location.href = "${ctx}/manage/viewFmPage.action";
			})
		}
	</script>
	<div id="wrapper">
		<div id="content_wrap">
			<div class="tabs_content">
				<div class="active_tab" id="tab1"></div>
				<div id="table_wrapper" style="width: 100%; overflow: auto;">
					<form id="uploadForm" method="post" enctype="multipart/form-data">
						<table class="table" cellpadding="0" cellspacing="0">
							<input type="hidden" name="fmId" id="fmId" value="${fm.id }" />
							<tr>
								<td>节目名称</td>
								<td><input id="title" name="title" style="width: 600px;"
									value="${fm.title }" /></td>
							</tr>
							<tr>
								<td>上传图片</td>
								<td><input id="fileid" type="file" value="选择上传图片"
									name="fujianFile" onchange="uploadImage()" /><font color=red>*上传根据网速不同，可能需要一段时间，请耐心等待</font>
									<div id="iconDiv">
										<c:if test="${!empty fm && !empty fm.iconUrl }">
											<img src="${fm.iconUrl }" />
										</c:if>
										<input type="hidden" id="iconUrl" value="${fm.iconUrl }" />
									</div></td>
							</tr>
							</form>
							<form id="uploadForm2" method="post"
								enctype="multipart/form-data">
							<tr>
								<td>上传节目(mp3文件)</td>
								<td><input id="fileid" type="file" value="选择上传节目"
									name="fujianFile" onchange="uploadFm()" /><font color=red>*上传根据网速不同，可能需要一段时间，请耐心等待</font>
									<div id="url">
										<c:if test="${!empty fm && !empty fm.url }">
											${fm.url }
										</c:if>
									</div></td>
							</tr>
							</form>
							<tr>
								<td></td>
								<td><input type="button" value="提交" onclick="createFm();" /></td>
							</tr>
						</table>
				</div>
			</div>
		</div>
	</div>
	</div>
</body>
</html>

